package ren.nearby.main;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;


import com.tencent.tinker.lib.tinker.TinkerInstaller;

import java.io.File;

import io.github.tonnyl.light.Light;
import ren.nearby.http.base.BaseActivity;

/**
 * Created by Administrator on 2018/4/25 0025.
 */

public class TinkerAct extends BaseActivity {
    String strPath;
    Button main_btn_tinker;
    Button main_btn_picture;
    ImageView main_iv_picture;


    @Override
    public int getContentView() {
        return R.layout.main_tiker;

    }





    @Override
    public void initView() {
        super.initView();
        builder
                .setIconLeft(R.mipmap.btn_back_white)
                .setBack(true)
                .setTitle(getResources().getString(R.string.main_tinker))
                .setBackgroundColor(R.color.colorPrimary)
                .setTitleColor(R.color.white)
                .build();



        strPath = getExternalCacheDir().getAbsolutePath() + File.separatorChar;
        main_btn_tinker = findViewById(R.id.main_btn_tinker);
        //添加热更新的代码-----------------------------------------------------------------start
        main_btn_picture = findViewById(R.id.main_btn_picture);
        main_iv_picture = findViewById(R.id.main_iv_picture);
        main_btn_picture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                main_iv_picture.setVisibility(View.VISIBLE);
                Light.info(main_btn_tinker, "show image ", Light.LENGTH_SHORT).show();
            }
        });
        //添加热更新的代码-----------------------------------------------------------------end
        //加载tinker
        main_btn_tinker.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                File pathFile = new File(strPath, "patch_signed_7zip.apk");
                if (pathFile.exists()) {
//                    TinkerManager.addPatch(pathFile.getAbsolutePath());
                    TinkerInstaller.onReceiveUpgradePatch(
                            getActivity().getApplicationContext(),
                            pathFile.getAbsolutePath());
                    Light.info(main_btn_tinker, "File Exists,Please wait a moment ", Light.LENGTH_SHORT).show();
                } else {
                    Light.error(main_btn_tinker, "File No Exists ", Light.LENGTH_SHORT).show();
                }
            }
        });
    }

}
